package org.hh.study.pooltest.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import thread.pool.core.executor.DynamicThreadPoolExecutor;
import thread.pool.core.executor.ThreadPoolBuilder;


@Configuration
public class ThreadPoolConfig {

    @Bean(name = "threadPoolExecutor")
    public DynamicThreadPoolExecutor threadPoolExecutor() {
        return ThreadPoolBuilder.builder()
                .setAlarmSize(2)
                .setTaskDescribe("测试专用线程池")
                .setDequeSize(8)
                .setRejectedExecutionHandler((r, executor) -> {
                    System.out.println("开始执行拒绝策略，线程池已经发生异常啦");
                })
                .build();
    }
}
